import App from './App'
import Vue from 'vue'

import { login } from "./request/apis/modules/user.js"

import { phone } from "./utils/modules/valid.js"
import { tip } from "./utils/modules/system.js"

import utils from "./utils/index.js"
Vue.prototype.$utils = utils
import apis from "./request/apis/index.js"
Vue.prototype.$apis = apis

import "./filters/index.js"

Vue.prototype.$go = (params, type) =>{
	if (typeof params === 'string') {
		if(type === "switch"){
			uni.switchTab({
				url: params
			})
		}else{
			uni.navigateTo({
				url: params
			})
		}
	}
	if (typeof params === 'object') {
		if(type === "switch"){
			uni.switchTab(params)
		}else{
			uni.navigateTo(params)
		}
	}
}

Vue.prototype.$call = (params) =>{
	if (uni.getStorageSync("token")) {
		if (phone(params)) {
			uni.makePhoneCall({
				phoneNumber: params
			});
		}else{
			tip("电话号码不合法，无法拨打");
		}
	}else{
		uni.navigateTo({
			url: "/pages/login"
		})
	}
}

Vue.prototype.$checkLogin = (callback) =>{
	if (uni.getStorageSync("token")) {
		if(callback){
			callback()
		}
	}else{
		uni.navigateTo({
			url: "/pages/login"
		})
	}
}

Vue.prototype.$back = () =>{
	uni.navigateBack()
}

Vue.prototype.$getImgPath = (name) =>{
	return "https://bchr-truck.oss-cn-hangzhou.aliyuncs.com/truck-info/" + name;
}

Vue.prototype.$dict = (key) =>{
	let dict = uni.getStorageSync("dict");
	let arr = [];
	for (var i = 0; i < dict.length; i++) {
		if(key === dict[i].settingType){
			arr.push(dict[i].settingValue)
		}
	}
	return arr;
}

Vue.config.productionTip = false
App.mpType = 'app'

const app = new Vue({
	...App
})
app.$mount()
